﻿using UnityEngine;
using System.Collections;

public class OpenDoorOnDirection : MonoBehaviour {
	public Material openMaterial, closedMaterial;
	public float alphaMin, alphaMax, angleMax;
	public string iconName;
	
	// Update is called once per frame
	void Update () {
		Color c;
		float alpha = Mathf.Min(Vector3.Angle(transform.up, Vector3.up) / angleMax, 1);
		alpha = (alpha * (alphaMax - alphaMin)) + alphaMin;
		c = new Color(1,1,1,alpha);
		if(transform.up == Vector3.up) {
			collider.enabled = false;
			foreach(Renderer r in GetComponentsInChildren<Renderer>()) {
				r.material = openMaterial;
				r.material.color = c;
			}
		} else {
			collider.enabled = true;
			foreach(Renderer r in GetComponentsInChildren<Renderer>()) {
				r.material = closedMaterial;
				r.material.color = c;
			}
		}
	}
	
}
